*===============================================================================*
*																				*
*		THIS DO FILE PRODUCES ONLINE APPENDIX TABLE A8 							*
* 		IN LONDONO-VELEZ AND QUERUBIN											*
*		"THE IMPACT OF EMERGENCY CASH ASSISTANCE IN A PANDEMIC: EXPERIMENTAL 	* 
* 		EVIDENCE FROM COLOMBIA", REVIEW OF ECONOMICS AND STATISTICS				*
*																				*
*		LAST MODIFIED: 2021-02-02												*
*																				*
*===============================================================================*

	
	use 	"${datadir}/main.dta", clear
	
	global 	cond_fin1_comp ""
	global 	cond_fsec_comp ""
	global 	cond_hlth_m_comp ""
	global 	cond_hlth_p_comp ""
	global 	cond_ipv_comp "if ipv2==1 & female==1"
	global 	cond_edu_comp "if edu0>0 & !missing(edu0)"
	global 	cond_covbeh_comp ""
	global 	cov8_comp ""
	global 	cond_state_comp ""	
	
	global 	cond2_fin1_comp "if"
	global 	cond2_fsec_comp "if"
	global 	cond2_hlth_m_comp "if"
	global 	cond2_hlth_p_comp "if"
	global 	cond2_ipv_comp "&"
	global 	cond2_edu_comp "&"
	global 	cond2_covbeh_comp "if"
	global 	cond2_cov8_comp "if"
	global 	cond2_state_comp "if"
	
	gen 	rural = 1-urban
	gen 	treated_rural = treated*(1-urban)
	label 	var treated_rural "Treatment x Rural (Mun)"
	gen 	treated_cod_rural = treated*cod_rural
	label 	var treated_cod_rural "Treatment x Rural (HH)"
	gen 	treated_nowork = treated*(1-inc)
	label 	var treated_nowork "Treatment x Did not Work (Feb 2020)"
	gen 	treated_victim = treated*victim
	label	var treated_victim "Treatment x Victim"
	
	sum 	sisben4 if !missing(sisben4), d
	gen 	poorest = .
	replace poorest = 1 if sisben4<=r(p50) & !missing(sisben4)
	replace poorest = 0 if sisben4>r(p50) & !missing(sisben4)
	sum 	sisben3 if missing(sisben4), d
	replace poorest = 1 if sisben3<=r(p50) & missing(sisben4)
	replace poorest = 0 if sisben3>r(p50) & missing(sisben4)
	gen 	treated_poorest = treated*poorest
	label 	var treated_poorest "Treatment x Poorest"

	
	foreach o of varlist fin1_comp {
	
			reghdfe `o' treated treated_2_2 transfer2_type_2 $control_lin ${cond_`o'} ${cond2_`o'} (departamento_fea_DPS_data!="BOLIVAR" & departamento_fea_DPS_data!="BOYACA" &departamento_fea_DPS_data!="CUNDINAMARCA" & departamento_fea_DPS_data!="N SANTANDER" & departamento_fea_DPS_data!="SANTANDER"), abs(codmunicipio $control_fe) vce(robust)
			outreg2  using "${figtabledir}/OnlineAppendix/TA8_a.xls", replace  label excel nocons bdec(3) keep(treated treated_2_2)
			reghdfe `o' treated treated_rural rural $control_lin ${cond_`o'}, abs(codmunicipio $control_fe) vce(robust)
			outreg2  using "${figtabledir}/OnlineAppendix/TA8_b.xls", replace label  excel nocons bdec(3) keep(treated_rural treated)
			reghdfe `o' treated treated_cod_rural cod_rural $control_lin ${cond_`o'}, abs(codmunicipio $control_fe) vce(robust)
			outreg2  using "${figtabledir}/OnlineAppendix/TA8_c.xls", replace label  excel nocons bdec(3) keep(treated_cod_rural treated)
			reghdfe `o' treated treated_nowork inc $control_lin ${cond_`o'}, abs(codmunicipio $control_fe) vce(robust)
			outreg2  using "${figtabledir}/OnlineAppendix/TA8_d.xls", replace label  excel nocons bdec(3) keep(treated treated_nowork)
			reghdfe `o' treated treated_victim victim $control_lin ${cond_`o'}, abs(codmunicipio $control_fe) vce(robust)
			outreg2  using "${figtabledir}/OnlineAppendix/TA8_e.xls", replace label  excel nocons bdec(3) keep(treated_victim treated)
			reghdfe `o' treated treated_poorest poorest $control_lin ${cond_`o'}, abs(codmunicipio $control_fe) vce(robust)
			outreg2  using "${figtabledir}/OnlineAppendix/TA8_f.xls", replace label  excel nocons bdec(3) keep(treated_poorest treated)
			}
		
		
	foreach o of varlist fsec_comp hlth_m_comp hlth_p_comp ipv_comp edu_comp cov8_comp state_comp {
	
			reghdfe `o' treated treated_2_2 transfer2_type_2 $control_lin ${cond_`o'} ${cond2_`o'} (departamento_fea_DPS_data!="BOLIVAR" & departamento_fea_DPS_data!="BOYACA" &departamento_fea_DPS_data!="CUNDINAMARCA" & departamento_fea_DPS_data!="N SANTANDER" & departamento_fea_DPS_data!="SANTANDER"), abs(codmunicipio $control_fe) vce(robust)
			outreg2  using "${figtabledir}/OnlineAppendix/TA8_a.xls", append label  excel nocons bdec(3) keep(treated treated_2_2)
			eststo `o'_rural: reghdfe `o' treated treated_rural rural $control_lin ${cond_`o'}, abs(codmunicipio $control_fe) vce(robust)
			outreg2  using "${figtabledir}/OnlineAppendix/TA8_b.xls", append label  excel nocons bdec(3) keep(treated_rural treated)
			eststo `o'_cod_rural: reghdfe `o' treated treated_cod_rural cod_rural $control_lin ${cond_`o'}, abs(codmunicipio $control_fe) vce(robust)
			outreg2  using "${figtabledir}/OnlineAppendix/TA8_c.xls", append label  excel nocons bdec(3) keep(treated_cod_rural treated)
			eststo `o'_nowork: reghdfe `o' treated treated_nowork inc $control_lin ${cond_`o'}, abs(codmunicipio $control_fe) vce(robust)
			outreg2  using "${figtabledir}/OnlineAppendix/TA8_d.xls", append label  excel nocons bdec(3) keep(treated treated_nowork)
			eststo `o'_victim: reghdfe `o' treated treated_victim victim $control_lin ${cond_`o'}, abs(codmunicipio $control_fe) vce(robust)
			outreg2  using "${figtabledir}/OnlineAppendix/TA8_e.xls", append label  excel nocons bdec(3) keep(treated_victim treated)
			eststo `o'_poorest: reghdfe `o' treated treated_poorest poorest $control_lin ${cond_`o'}, abs(codmunicipio $control_fe) vce(robust)
			outreg2  using "${figtabledir}/OnlineAppendix/TA8_f.xls", append label  excel nocons bdec(3) keep(treated_poorest treated)
		
			}
			
